<template>
    <div>
<h1>会员信息修改</h1>
<table class="table">
    <tbody>
        <tr>
            <td>会员名称</td>
            <td>
                <input type="text" v-model="data.hyName">
            </td>
        </tr>

        <tr>
            <td>密码</td>
            <td>
                <input type="text" v-model="data.password">
            </td>
        </tr>

        <tr>
            <td>会员状态</td>
            <td>
               <input type="radio" :value="true" v-model="data.hyState">启用
               <input type="radio" :value="false" v-model="data.hyState">禁用
            </td>
        </tr>

        <tr>
            <td>会员年龄</td>
            <td>
                <input type="text" v-model="data.age">
            </td>
        </tr>

        <tr>
            <td>会员头像</td>
            <td>
               <input type="file" @change="sc">
               <img :src="'https://localhost:7127/'+data.tuPian" style="height: 60px;width: 60px;" >
            </td>
        </tr>

        <tr>
            <td>会员等级</td>
            <td>
               <select v-model="data.djid">
                <option v-for="a in ba" :value="a.dId">{{ a.djName }}</option>
               </select>
            </td>
        </tr>

        <tr>
            <td></td>
            <td>
                <input type="button" value="修改" @click="xiu">
            </td>
        </tr>
    </tbody>
</table>
    </div>
</template>



<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { usebbbStore } from '@/stores/sb';
import { useRouter,useRoute} from 'vue-router';
const route=useRoute()
const router=useRouter()
const bbb=usebbbStore()
onMounted(()=>{
   
    bang()
    fan()
})

//反填
const fan=()=>{
    var dd=route.query.id
    axios.get("https://localhost:7127/api/Hy/FanHy",{params:{id:dd}}).then(res=>{
        data.value=res.data
    })
}


//上传
const sc=(va:any)=>{
    var a=va.target.files[0]
    var b=new FormData()  

    b.append("file",a);
    debugger
    if(a.type!='image/jpeg'&&a.type!='image/jpeg'){
        alert("图片类型不允许")
        return
    }
    if(a.size>1024*1024*2){
        alert("上传大小不得超过2MB")
        return
    }

    axios.post("https://localhost:7127/api/Hy/SC",b).then(res=>{
        data.value.tuPian=res.data
    })
}

//绑定的m
const ba=ref([{
    "dId": 0,
    "djName": "",
    "djState": null
  }])
//绑定
  const bang=()=>{
    axios.get("https://localhost:7127/api/Dj/GetAll").then(res=>{
     ba.value=res.data
    })
  }
//修改
  const xiu=()=>{
    axios.put("https://localhost:7127/api/Hy/XiuHy",data.value).then(res=>{
       if(res.data==-1){
        alert("会员昵称已存在");
        return
       }
       
        if(res.data>0){
            alert("修改成功");
            router.push({path:'/showhy'})
        }else{
            alert("修改失败");
        }
    })
  }
//m
  const data=ref({
  "hyId": 0,
  "hyName": "",
  "password": "",
  "djid": 0,
  "age": 0,
  "tuPian": "",
  "hyState": null
})
</script>

<style scoped>

</style>